package com.gitee.wsl.data.observer

/**
 * Definition of the contract for implementing listeners to receive [DataChangeEvent]s from a [Cache].
 */
 fun interface DataChangedEventListener<Key, Value> {
    /**
     * Invoked on [DataChangeEvent] firing.
     *
     * Cache entry event firing behaviors for mutative methods:
     *
     * | Initial value    | Operation                | New value | Event                            |
     * |:-----------------|:-------------------------|:----------|:---------------------------------|
     * | {}               | put(K, V)                | {K: V}    | Created(K, V)                    |
     * | {K: V1}          | put(K, V2)               | {K: V2}   | Updated(K, V1, V2)               |
     * | {K: V}           | invalidate(K)            | {}        | Removed(K, V)                    |
     * | {K1: V1, K2: V2} | invalidateAll()          | {}        | Removed(K1, V1), Removed(K2, V2) |
     * | {K: V}           | any operation, K expired | {}        | Expired(K, V)                    |
     * | {K1: V1}         | put(K2, V2), K1 evicted  | {K2: V2}  | Created(K2, V2), Evicted(K1, V1) |
     *
     */
     fun onEvent(event: DataChangeEvent<Key, Value>)
}